package com.squapsource.project_euler;

public class Problem8 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		long start = System.nanoTime();
		String testString = "73167176531330624919225119674426574742355349194934969835203127"
				+ "74506326239578318016984801869478851843858615607891129494954595017379583319"
				+ "52853208805511125406987471585238630507156932909632952274430435576689664895"
				+ "04452445231617318564030987111217223831136222989342338030813533627661428280"
				+ "64444866452387493035890729629049156044077239071381051585930796086670172427"
				+ "12188399879790879227492190169972088809377665727333001053367881220235421809"
				+ "75125454059475224352584907711670556013604839586446706324415722155397536978"
				+ "17977846174064955149290862569321978468622482839722413756570560574902614079"
				+ "72968652414535100474821663704844031998900088952434506585412275886668811642"
				+ "71714799244429282308634656748139191231628245861786645835912456652947654568"
				+ "28489128831426076900422421902267105562632111110937054421750694165896040807"
				+ "19840385096245544436298123098787992724428490918884580156166097919133875499"
				+ "20052406368991256071760605886116467109405077541002256983155200055935729725"
				+ "71636269561882670428252483600823257530420752963450";
		int maxProduct = 0;
		for (int i = 0; i < 996; i++) {
			int tempProduct = getProduct(testString.substring(i, i + 5));
			if (tempProduct > maxProduct)
				maxProduct = tempProduct;
		}
		System.out.println(maxProduct + " in " + (System.nanoTime() - start));

	}

	private static int getProduct(String testString) {
		return Character.getNumericValue(testString.charAt(0))
				* Character.getNumericValue(testString.charAt(1))
				* Character.getNumericValue(testString.charAt(2))
				* Character.getNumericValue(testString.charAt(3))
				* Character.getNumericValue(testString.charAt(4));
	}

}
